package serial;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.io.Serializable;

class A implements Serializable {
	private String s;
	public A(String s_in){
		s = s_in;
	}
	public String toString(){
		return "[" + s + "]";
	}
}

public class UseSerialization {

	public static void main(String[] args) {
		A a = new A("Hello");
		
		try {
			FileOutputStream fos = new FileOutputStream("src/serial/OutputFile.object");
			ObjectOutputStream p = new ObjectOutputStream( fos );
			p.writeObject( a );
			p.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} 
		
		try {
			FileInputStream fis = new FileInputStream("src/serial/OutputFile.object");
			ObjectInputStream ois = new ObjectInputStream( fis );
			A b = (A) ois.readObject();
			ois.close();
			
			System.out.println(" b is " + b);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		
		
		
	}
}
